<?php
/**
 * Created by PhpStorm.
 * User: simon
 * Date: 2016/4/29
 * Time: 9:44
 */

namespace App\Utils;


class ResourceUtils
{

    static public function toInternets(&$list, $properties, $group_folder = "")
    {
        if (is_string($properties)) {
            $properties = [$properties];
        }
        $size = count($list);
        for ($i = 0; $i < $size; $i++) {
            foreach ($properties as $property) {
                $list[$i][$property] = self::toInternet($list[$i][$property], $group_folder);
            }
        }
    }

    static public function toInternet($relativePath, $group_folder = "")
    {
        if (empty($relativePath)) {
            return "";
        }
        if (self::isInternetUrl($relativePath)) {
            return $relativePath;
        }

        $appPath = "app/files/";
        if (substr($relativePath, 0, 1) == "/") {
            $relativePath = substr($relativePath, 1);
        }
        $url = env("UI_SITE_URL", "http://me.kids-company.com/") . $appPath . $group_folder . $relativePath;
        return $url;
    }

    static public function isInternetUrl($url)
    {
        $len = strlen($url);
        if ($len > 7) {
            if ("http://" == strtolower(substr($url, 0, 7))) {
                return true;
            }
        }
        return false;
    }

    static public function fixTeacherImage($relativePath)
    {
        return self::toInternet($relativePath, "");
    }

    static public function fixSpecialtyImage($relativePath)
    {
        return self::toInternet($relativePath, "");
    }

    static public function fixScrollImage($relativePath)
    {
        return self::toInternet($relativePath, "");
    }

    static public function fixEnvImage($relativePath)
    {
        return self::toInternet($relativePath, "");
        // return self::toInternet($relativePath, "env_images/");
    }
}